package com.ruoyi.iptv.video.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.iptv.video.mapper.IptvVideoTypeMapper;
import com.ruoyi.iptv.video.domain.IptvVideoType;
import com.ruoyi.iptv.video.service.IIptvVideoTypeService;
import com.ruoyi.common.core.text.Convert;

/**
 * 点播分类Service业务层处理
 * 
 * @author 玉念聿辉
 * @date 2021-10-20
 */
@Service
public class IptvVideoTypeServiceImpl implements IIptvVideoTypeService 
{
    @Autowired
    private IptvVideoTypeMapper iptvVideoTypeMapper;

    /**
     * 查询点播分类
     * 
     * @param id 点播分类主键
     * @return 点播分类
     */
    @Override
    public IptvVideoType selectIptvVideoTypeById(Long id)
    {
        return iptvVideoTypeMapper.selectIptvVideoTypeById(id);
    }

    /**
     * 查询点播分类列表
     * 
     * @param iptvVideoType 点播分类
     * @return 点播分类
     */
    @Override
    public List<IptvVideoType> selectIptvVideoTypeList(IptvVideoType iptvVideoType)
    {
        return iptvVideoTypeMapper.selectIptvVideoTypeList(iptvVideoType);
    }

    /**
     * 新增点播分类
     * 
     * @param iptvVideoType 点播分类
     * @return 结果
     */
    @Override
    public int insertIptvVideoType(IptvVideoType iptvVideoType)
    {
        iptvVideoType.setCreateTime(DateUtils.getNowDate());
        return iptvVideoTypeMapper.insertIptvVideoType(iptvVideoType);
    }

    /**
     * 修改点播分类
     * 
     * @param iptvVideoType 点播分类
     * @return 结果
     */
    @Override
    public int updateIptvVideoType(IptvVideoType iptvVideoType)
    {
        iptvVideoType.setUpdateTime(DateUtils.getNowDate());
        return iptvVideoTypeMapper.updateIptvVideoType(iptvVideoType);
    }

    /**
     * 批量删除点播分类
     * 
     * @param ids 需要删除的点播分类主键
     * @return 结果
     */
    @Override
    public int deleteIptvVideoTypeByIds(String ids)
    {
        return iptvVideoTypeMapper.deleteIptvVideoTypeByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除点播分类信息
     * 
     * @param id 点播分类主键
     * @return 结果
     */
    @Override
    public int deleteIptvVideoTypeById(Long id)
    {
        return iptvVideoTypeMapper.deleteIptvVideoTypeById(id);
    }

    /**
     * 查询点播分类树列表
     * 
     * @return 所有点播分类信息
     */
    @Override
    public List<Ztree> selectIptvVideoTypeTree()
    {
        List<IptvVideoType> iptvVideoTypeList = iptvVideoTypeMapper.selectIptvVideoTypeList(new IptvVideoType());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (IptvVideoType iptvVideoType : iptvVideoTypeList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(iptvVideoType.getId());
            ztree.setpId(iptvVideoType.getParentId());
            ztree.setName(iptvVideoType.getName());
            ztree.setTitle(iptvVideoType.getName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
